from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class lineditDemo(QWidget):
    def __init__(self,parent=None):
        super(lineditDemo,self).__init__(parent)
        self.setWindowTitle("Qlinedit例子")
        flo=QFormLayout()
        pIntLineEdit=QLineEdit()
        pDoubleLineEdit=QLineEdit()
        PValidatorLineEdit=QLineEdit()
        flo.addRow("整型",pIntLineEdit)
        flo.addRow("浮点型", pDoubleLineEdit)
        flo.addRow("字母和数字", PValidatorLineEdit)
        pIntLineEdit.setPlaceholderText("整型")
        pDoubleLineEdit.setPlaceholderText("浮点型")
        PValidatorLineEdit.setPlaceholderText("字母和数字")
        pintVal=QIntValidator(self)
        pintVal.setRange(1,99)#整型[1,99]
        pdoubleVal=QDoubleValidator(self)
        pdoubleVal.setRange(-125,125)

        pdoubleVal.setNotation(QDoubleValidator.StandardNotation)
        pdoubleVal.setDecimals(2) #范围 -125 125 精度是小数点后两位
        reg=QRegExp("[a-zA-Z0-9]+$")
        pVailtor=QRegExpValidator(self)
        pVailtor.setRegExp(reg)
        #设置验证器
        pIntLineEdit.setValidator(pintVal)
        pDoubleLineEdit.setValidator(pdoubleVal)
        PValidatorLineEdit.setValidator(pVailtor)

        self.setLayout(flo)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = lineditDemo()
    win.show()
    sys.exit(app.exec_())